﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        enum enrole
        {
            刘 = 1,
            孙 = 2,
            曹 = 3
        }
        enum enmora
        {
            石头 = 1,
            剪刀 = 2,
            布 = 3
        }
        static void Main(string[] args)
        {
            Console.WriteLine("********************");
            Console.WriteLine("*****猜拳，开始*****");
            Console.WriteLine("********************");
            Console.WriteLine("出拳:1.剪刀 2.石头 3.布");
            Console.WriteLine("请选择你的对手《1.刘备  2.孙权  3.曹操》");
            int numname = int.Parse(Console.ReadLine());
            String npc = Enum.GetName(typeof(enrole), numname);
            character ch = new character(npc);
            Console.WriteLine("请输入你的名字");
            string playn = Console.ReadLine();
            Console.WriteLine(playn + "VS" + npc);
            Console.WriteLine("开始游戏(y/n)");
            char char1 = Convert.ToChar(Console.ReadLine());
            if (char1 == 'y' || char1 == 'Y')
            {
                WinMora(ch, npc, playn);
            }
            else if(char1 == 'n' || char1 == 'N')
            {
                Console.WriteLine("退出程序");
                System.Environment.Exit(0);
            }
        }
        private static void WinMora(character role, string npc, string playn)
        {
            int draw = 0;
            int NPCwin = 0;
            int Playwin = 0;

            while (true)
            {
                Console.WriteLine("请出拳1.石头2.剪刀3.布 ---请输入相应的数字");
                int Moranum = int.Parse(Console.ReadLine());
                string playMore = Enum.GetName(typeof(enmora), Moranum);
                Console.WriteLine(playn + "出拳" + playMora);
                role.Write();

                if (role.StrMora == playMora)
                {
                    Console.WriteLine("平局");
                    draw = draw + 1;
                }
                else if (playMora == "石头" && role.StrMora == "剪刀" || playMora == "布" && role.StrMora == "石头" || playMora == "剪刀" && role.StrMora == "布")
                {
                    Console.WriteLine("恭喜您，你赢了");
                    Playwin = Playwin + 1;
                }
                else if (role.StrMora == "剪刀" && playMora == "布" || role.StrMora == "石头" && playMora == "剪刀" || role.StrMora == "布" && playMora == "石头")
                {
                    Console.WriteLine("你输了");
                    NPCwin = NPCwin + 1;
                }
                else if (playMora != "石头" || playMora != "剪刀" || playMora != "布")
                {
                    NPCwin = NPCwin + 1;
                    Console.WriteLine("玩家，出拳不符合规则默认判负");
                }

                Console.WriteLine("是否开始下一局(y/n)");
                char char2 = Convert.ToChar(Console.ReadLine());
                if (char2 == 'y' || char2 == 'Y')
                {

                }
                else if (char2 == 'n' || char2 == 'N')
                {
                    Console.WriteLine("结束游戏");
                    Console.WriteLine("===========================");
                    Console.WriteLine(playn + " VS " + npc);
                    Console.WriteLine("对战次数" + (Playwin + NPCwin + draw));
                    Console.WriteLine("姓名     得分");
                    Console.WriteLine($"{playn}     {Playwin}");
                    Console.WriteLine($"{npc}     {NPCwin}");
                    if (Playwin > NPCwin)
                    {
                        Console.WriteLine("玩家 " + playn + " 胜出，举世同庆");
                    }
                    else if (NPCwin > Playwin)
                    {
                        Console.WriteLine("电脑" + npc + "胜出，棋差一手");
                    }
                    else
                    {
                        Console.WriteLine("平局");
                    }
                    break;
                }
            }
        }
    }
}
